
using System;
using System.Linq;
using Csla;
using Csla.Data;
using Csla.Security;
using Csla.Validation;

namespace HousingInfo.Library
{ 
	public partial class NewsBussinessBO : Csla.BusinessBase<NewsBussinessBO>
	{

		#region Authorization Rules
		protected override void AddAuthorizationRules()
		{
			//TODO: Define authorization rules in NewsBussinessBO
			//AuthorizationRules.AllowRead(NewsBussinessIDProperty, "NewsBussinessBOReadGroup");
			//AuthorizationRules.AllowRead(UserNameProperty, "NewsBussinessBOReadGroup");
			//AuthorizationRules.AllowRead(BussinessNameProperty, "NewsBussinessBOReadGroup");
			//AuthorizationRules.AllowRead(BussinessAddressProperty, "NewsBussinessBOReadGroup");
			//AuthorizationRules.AllowRead(BussinessWebsiteProperty, "NewsBussinessBOReadGroup");
			//AuthorizationRules.AllowRead(BussinessPhoneProperty, "NewsBussinessBOReadGroup");
			//AuthorizationRules.AllowRead(UrlImageProperty, "NewsBussinessBOReadGroup");
			//AuthorizationRules.AllowRead(EmailProperty, "NewsBussinessBOReadGroup");
			//AuthorizationRules.AllowRead(IsExtensionProperty, "NewsBussinessBOReadGroup");
			//AuthorizationRules.AllowRead(CreatedDateProperty, "NewsBussinessBOReadGroup");
			//AuthorizationRules.AllowRead(UpdatedDateProperty, "NewsBussinessBOReadGroup");
			//AuthorizationRules.AllowRead(ExpireDateProperty, "NewsBussinessBOReadGroup");
			//AuthorizationRules.AllowRead(IsActiveProperty, "NewsBussinessBOReadGroup");

			//AuthorizationRules.AllowWrite(UserNameProperty, "NewsBussinessBOWriteGroup");
			//AuthorizationRules.AllowWrite(BussinessNameProperty, "NewsBussinessBOWriteGroup");
			//AuthorizationRules.AllowWrite(BussinessAddressProperty, "NewsBussinessBOWriteGroup");
			//AuthorizationRules.AllowWrite(BussinessWebsiteProperty, "NewsBussinessBOWriteGroup");
			//AuthorizationRules.AllowWrite(BussinessPhoneProperty, "NewsBussinessBOWriteGroup");
			//AuthorizationRules.AllowWrite(UrlImageProperty, "NewsBussinessBOWriteGroup");
			//AuthorizationRules.AllowWrite(EmailProperty, "NewsBussinessBOWriteGroup");
			//AuthorizationRules.AllowWrite(IsExtensionProperty, "NewsBussinessBOWriteGroup");
			//AuthorizationRules.AllowWrite(CreatedDateProperty, "NewsBussinessBOWriteGroup");
			//AuthorizationRules.AllowWrite(UpdatedDateProperty, "NewsBussinessBOWriteGroup");
			//AuthorizationRules.AllowWrite(ExpireDateProperty, "NewsBussinessBOWriteGroup");
			//AuthorizationRules.AllowWrite(IsActiveProperty, "NewsBussinessBOWriteGroup");
		}

		protected static void AddObjectAuthorizationRules()
		{
			//TODO: Define object-level authorization rules of NewsBussinessBO
			//AuthorizationRules.AllowCreate(typeof(NewsBussinessBO), "NewsBussinessBOCreateGroup"));
			//AuthorizationRules.AllowEdit(typeof(NewsBussinessBO), "NewsBussinessBOEditGroup"));
			//AuthorizationRules.AllowDelete(typeof(NewsBussinessBO), "NewsBussinessBODeleteGroup"));
		}
		#endregion //Authorization Rules
		private void AssignParentKey(HousingInfo.DataLinQ.NewsBussiness data)
		{
			 //data.ParentId = ReadProperty<ParentBO>(ParentBOProperty).Id;
		}
        #region Kiem tra su ton tai cua ten doanh nghiep
        public static bool CheckBussinessNameExist(string bussinessname)
        {
            int count = 0;
            using (var mgr = ContextManager<HousingInfo.DataLinQ.HousingInfoDataContext>
                        .GetManager(Database.HousingInfoConnection))
            {
                count = mgr.DataContext.NewsBussinesses.Count(u => u.BussinessName == bussinessname);
            }
            return (count > 0);

        }
        #endregion //Kiem tra su ton tai cua username
	}
}
